package com.xiaotu.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.xiaotu.mapper.CoordinateMapper;
import com.xiaotu.model.RoomPlayerCoordinateModel;
import com.xiaotu.service.CoordinateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 张晓
 * @create 2021-10-18 21:58
 */
@Service
public class CoordinateServiceImpl implements CoordinateService {

    @Autowired
    private CoordinateMapper coordinateMapper;

    @Transactional
    @Override
    public void saveCoordinate(RoomPlayerCoordinateModel coordinateModel) {
        if (ObjectUtil.isNull(coordinateModel.getRpcId())) {
            coordinateMapper.insert(coordinateModel);
        } else {
            coordinateMapper.updateByPrimaryKey(coordinateModel);
        }
    }

    @Transactional
    @Override
    public void clearHistoryCoordinate(Integer roomId) {
        coordinateMapper.clearHistoryCoordinate(roomId);
    }
}
